package com.cfuture.xiaozhi.smarthome.adapter;

import com.cfuture.xiaozhi.smarthome.R;
import com.cfuture.xiaozhi.smarthome.common.ui.Util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 左边菜单按钮
 * 
 * @author cfuture_小智
 * @Description
 */
public class LeftMenuListAdapter extends BaseAdapter {
	public String[] data;

	private Context mContext;
	private LayoutInflater mInfalter;
	private int icons[] = { R.drawable.riguangdeng, R.drawable.chuanglian,
			R.drawable.kongtiao, R.drawable.kongtiao, R.drawable.kaiguan };
	private int selectPosition = 1;

	/**
	 * 
	 * @param c
	 * @param data
	 *            电器类型
	 */
	public LeftMenuListAdapter(Context c, String[] data) {
		mContext = c;
		mInfalter = LayoutInflater.from(mContext);
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.length;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInfalter.inflate(R.layout.left_menu_list_item, null);
			holder = new ViewHolder();
			holder.ivIcon = (ImageView) convertView
					.findViewById(R.id.menu_list_item_iv_icon);
			holder.tvName = (TextView) convertView
					.findViewById(R.id.menu_list_item_tv_name);
			holder.ibSelectState = (ImageButton) convertView
					.findViewById(R.id.menu_list_item_iv_isselect);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (selectPosition == position + 1) {
			holder.ibSelectState.setVisibility(View.VISIBLE);
		} else {
			holder.ibSelectState.setVisibility(View.INVISIBLE);
		}
		holder.tvName.setText(data[position]);
		holder.ivIcon.setImageResource(icons[position]);
		return convertView;
	}

	static class ViewHolder {
		TextView tvName;
		ImageButton ibSelectState;
		ImageView ivIcon;
	}
}
